#!/usr/bin/env python

from twisted.internet import reactor, defer
from connectiontest import testConnect

def handleAllResults(results, ports):
    #print results
    #print ports
    for port, resultInfo in zip(ports, results):
        success, result = resultInfo
        #print result
        if success:
           print "Connected to port %i" % port
    reactor.stop()
    
import sys
host = sys.argv[1]
ports = range(1,100)
testers = [testConnect(host,port) for port in ports]
defer.DeferredList(testers, consumeErrors=True).addCallback(handleAllResults, ports) 
reactor.run()